home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / SDKs / Now Utilities Plug Ins 6.0 / API Stuff / Now Shortcuts Plug Ins ƒ / File Locking ƒ / Main.c < prev    next >
C/C++ Source or Header  |  1996-03-07  |  3KB  |  120 lines

  1. // Lock File Plug In for Now Utilities 6.0
  2. // © Now Software, Inc.
  3. // 
  4. // written by hac
  5. // 3/4/96
  6. //
  7. // This module installs three grouped menu items in the Now Tabs popup:
  8. //   - Lock
  9. //   - Unlock
  10.  
  11.  
  12.  
  13. #include "Main.h"
  14.  
  15. #define        kLock        2
  16. #define        kUnlock        3
  17.  
  18. pascal void main(PlugInInformation *plugInInformation)
  19. {
  20.     plugInInformation->version = kPlugInInformationVersionOne;
  21.     plugInInformation->plugInType = kFileLockingPlugInType;
  22.     plugInInformation->PrepareMenu = &PrepareMenu;
  23.     plugInInformation->HandleMenuItemSelected = &HandleMenuItemSelected;
  24. }
  25.  
  26. pascal void PrepareMenu(InstantAccessInformation *information, short asPreview)
  27. {
  28.     MenuSelectResultStructure            mrs;
  29.  
  30.     MenuItemInformation    menuItem;    
  31.     
  32.     // add a divider line above
  33.     menuItem.version = kMenuItemInformationVersionOne;
  34.     menuItem.classification = kMiscellaneousClassification;
  35.     menuItem.type = kDividerMenuItemType;
  36.     menuItem.id = 1;
  37.     menuItem.enabled = false;
  38.     menuItem.style = 0;
  39.     menuItem.mark = 0;
  40.     menuItem.hasSubMenu = FALSE;
  41.     menuItem.subMenu = nil;
  42.     menuItem.refCon = 0;
  43.     menuItem.owningPlugInType = kFileLockingPlugInType;
  44.     
  45.     (*information->AddMenuItem)(&menuItem);
  46.  
  47.     // add the lock menu item        
  48.  
  49.     BlockMove("\pLock", menuItem.text, kMenuItemTextSize);
  50.  
  51.     menuItem.type = kTextMenuItemType;
  52.     menuItem.id = 2;
  53.     menuItem.enabled = true;
  54.     
  55.     (*information->AddMenuItem)(&menuItem);
  56.  
  57.     // add the unlock menu item        
  58.  
  59.     BlockMove("\pUnlock", menuItem.text, kMenuItemTextSize);
  60.  
  61.     menuItem.type = kTextMenuItemType;
  62.     menuItem.id = 3;
  63.     menuItem.enabled = true;
  64.     
  65.     (*information->AddMenuItem)(&menuItem);
  66.  
  67.     // add a divider line below
  68.     menuItem.type = kDividerMenuItemType;
  69.     menuItem.id = 5;
  70.     menuItem.enabled = false;
  71.     
  72.     (*information->AddMenuItem)(&menuItem);
  73. }
  74.  
  75. pascal void CleanUpAfterMenuSelect(InstantAccessInformation *information, short asPreview)
  76. {
  77.     //hmmmm....
  78. }
  79.  
  80. pascal void HandleMenuItemSelected(InstantAccessInformation *information, MenuItemInformation *menuItem)
  81. {
  82.     OSErr                        err            = noErr;
  83.     short                        index;
  84.     short                        itemCount;
  85.     FSSpec                        spec;
  86.     void*                        reference;
  87.  
  88.     // count the number of selected items
  89.     itemCount = (*information->CountSelectedItems)();
  90.  
  91.     // index through each one
  92.     for (index = 0; index < itemCount; index++) {
  93.  
  94.         // get the item reference
  95.         reference = (*information->GetNthSelectedItemReference)(index);
  96.  
  97.         // get the file spec
  98.         (*information->GetSelectedItemFileSpec)(reference, &spec);
  99.  
  100.         switch (menuItem->id) {
  101.             
  102.             case kLock:
  103.                 err = FSpSetFLock(&spec);
  104.                 break;
  105.     
  106.             case kUnlock:
  107.                 err = FSpRstFLock(&spec);
  108.                 break;
  109.     
  110.             otherwise:
  111.                 break;
  112.     
  113.         }
  114.  
  115.     }
  116.  
  117. error:;
  118.  
  119. }
  120.